//
//  HCFindViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2016/12/16.
//  Copyright © 2016年 WillyZhao. All rights reserved.
//

#import "HCFindViewController.h"

#import "HCFindContentView.h"

#import "HCFindModel.h"

#import "XFWkwebView.h"

#import <AFNetworking.h>

#import "HCAllUsedModel.h"
#import "HCEveryDayModel.h"

@interface HCFindViewController () <HCFindContentViewDelegate> {
    HCFindModel *model_find;
    HCFindContentView *findView;
    
    HCEveryDayModel *model_every;
    HCAllUsedModel *model_alluse;
    
    NSArray *navDatas;
}

@end

@implementation HCFindViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.textTitle = @"发现";
    
    [self loadSubViews];
    self.dataRequest.delegate = self;
    
    [self.dataRequest postHC_Find];
    
    
    
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {

    if (aType == HC_EVERYDAY_TYPE) {
        model_every = [[HCEveryDayModel alloc] initWithDictionary:dictionary error:nil];
        findView.model = model_every;
        [self.dataRequest postHC_ALLUSE];

    }else if (aType == HC_ALLUSE_TYPE) {
        model_alluse = [[HCAllUsedModel alloc] initWithDictionary:dictionary error:nil];
        findView.model = model_alluse;
        [self.dataRequest post_HCFondProject];
        
    }else if(aType == HC_FIND){
        model_find = [[HCFindModel alloc] initWithDictionary:dictionary error:nil];
        findView.model = model_find;
        
        [self.dataRequest postHC_EveryDay];

    }else{
        navDatas = [NSArray arrayWithArray:dictionary[@"project"]];
        NSMutableArray *arr = [NSMutableArray array];
        
        for (NSInteger i = 0; i<navDatas.count; i++) {
            NSString *ss = [NSString stringWithFormat:@"%@",navDatas[i][@"name"]];
            [arr addObject:ss];
        }
        
        findView.header.vb.namesArray = arr;
    }
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    NSLog(@"发现请求失败");
}

-(void)loadSubViews {
    findView = [[HCFindContentView alloc] initWithFrame:CGRectMake(0, 0, self.centerView.frame.size.width, self.centerView.frame.size.height)];
    findView.delegate = self;
    findView.backgroundColor = [UIColor whiteColor];
    [self.centerView addSubview:findView];
}

-(void)HCFindContentViewClickedContent:(NSIndexPath *)indexPath view:(NSInteger)index {
    if (index == 1) {
        NSLog(@"热推");
        HCFindData *data = model_find.f_index[indexPath.row];
        [self pushChildrenViewController:@"HCFindDetailViewController" parameterObject:data.url dataObject:@"热推"];
    }else if (index == 2) {
        NSLog(@"每日特价");
        HCEveryDayData *data = model_every.all_used[indexPath.row];
        [self pushChildrenViewController:@"HCFindDetailViewController" parameterObject:data.url dataObject:@"每日特价"];
    }else if (index == 3) {
        NSLog(@"大家都在用");
        HCAllUsedData *data = model_alluse.sp_offer[indexPath.row];
        [self pushChildrenViewController:@"HCFindDetailViewController" parameterObject:data.url dataObject:@"大家都在用"];
    }
}

-(void)HCFindContentViewClicked:(HCFindHeaderButton *)btn {
    switch (btn.tag) {
        case 1:
            //积分商城
        {
//            TODO
            [self pushChildrenViewController:@"HCGoodsScoreViewController" parameterObject:nil dataObject:nil];            
        }
            break;
        case 2:
            //门店热榜
        {
            NSLog(@"门店热榜");
            [self pushChildrenViewController:@"HCHotStoreViewController" parameterObject:nil dataObject:nil];
        }
            break;
        case 3:
            //店家推荐
        {
            NSLog(@"店家推荐");
            [self pushChildrenViewController:@"HCStoreRecommendViewController" parameterObject:nil dataObject:nil];
        }
            break;
        case 4:
            //更多门店
        {
            NSLog(@"更多门店");
            
        }
            break;
        default:
            break;
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 图片点击方法
-(void)HCFindImageClicked:(NSInteger)index {
    [self pushChildrenViewController:@"HCNvaDetailViewController" parameterObject:navDatas dataObject:[NSString stringWithFormat:@"%ld",index]];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
